/**
 * @author 黄波
 * 创建日期：2011Oct 11, 2011
 * TODO// N/A
 */
package com.platform.njcc.action;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.platform.common.bo.CommonBo;
import com.platform.pojo.SchoolProperty;
import com.platform.pojo.UserGroup;
import com.platform.pojo.UserInfo;
import com.platform.user.bo.UserBo;

/**
 * 加载用户信息
 */
public class LoadUserInfoAction extends NJCCSuport {

	private UserInfo user;
	private String regTime;
	private String lastLoginTime;
	private UserGroup group;				//用户组
	private SchoolProperty department;		//系部
	private SchoolProperty professional;	//专业
	private SchoolProperty grade;			//年级
	private SchoolProperty clazz;			//班级
	private List<UserGroup> groups;				//目前系统中的所有用户组
	private List<SchoolProperty> departmentlist;	//查询所有的系部信息
	
	@Override
	public String execute() throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		HttpSession session = ServletActionContext.getRequest().getSession();
		user = (UserInfo) session.getAttribute("user");
		if(user == null || user.getId() == null || user.getId().intValue() == 0) {
			out.flush();
			out.write("<script>alert('请先登录！');history.back();</script>");
			out.close();
			return null;
		}
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if(user.getRegTime() != null) {
			regTime = format.format(user.getRegTime());
		}
		if(user.getLastLoginTime() != null) {
			lastLoginTime = format.format(user.getLastLoginTime());
		}
		if(user.getGroupId() != null) {
			group = UserBo.getInstance().getUserGroup(user.getGroupId().toString());
		}
		if(user.getDepartmentId() != null) {
			department = CommonBo.getInstance().getSchoolProperty(user.getDepartmentId().toString());
		}
		if(user.getProfessionalId() != null) {
			professional = CommonBo.getInstance().getSchoolProperty(user.getProfessionalId().toString());
		}
		if(user.getGradeId() != null) {
			grade = CommonBo.getInstance().getSchoolProperty(user.getGradeId().toString());
		}
		if(user.getClassId() != null) {
			clazz = CommonBo.getInstance().getSchoolProperty(user.getClassId().toString());
		}
		groups = UserBo.getInstance().getGroups();
		//获得系部初始化时系部列表
		if(department != null) {
			departmentlist = CommonBo.getInstance().getSchoolProperties(department.getSuperId().toString());
		}
		return SUCCESS;
	}

	public List<UserGroup> getGroups() {
		return groups;
	}
	public void setGroups(List<UserGroup> groups) {
		this.groups = groups;
	}
	public UserInfo getUser() {
		return user;
	}
	public void setUser(UserInfo user) {
		this.user = user;
	}
	public String getRegTime() {
		return regTime;
	}
	public void setRegTime(String regTime) {
		this.regTime = regTime;
	}
	public String getLastLoginTime() {
		return lastLoginTime;
	}
	public void setLastLoginTime(String lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}
	public UserGroup getGroup() {
		return group;
	}
	public void setGroup(UserGroup group) {
		this.group = group;
	}
	public SchoolProperty getDepartment() {
		return department;
	}
	public void setDepartment(SchoolProperty department) {
		this.department = department;
	}
	public SchoolProperty getProfessional() {
		return professional;
	}
	public void setProfessional(SchoolProperty professional) {
		this.professional = professional;
	}
	public SchoolProperty getGrade() {
		return grade;
	}
	public void setGrade(SchoolProperty grade) {
		this.grade = grade;
	}
	public SchoolProperty getClazz() {
		return clazz;
	}
	public void setClazz(SchoolProperty clazz) {
		this.clazz = clazz;
	}

	public List<SchoolProperty> getDepartmentlist() {
		return departmentlist;
	}

	public void setDepartmentlist(List<SchoolProperty> departmentlist) {
		this.departmentlist = departmentlist;
	}
	
}
